<?php /* SVN: $Id: index.ctp 2879 2010-08-27 11:08:48Z sakthivel_135at10 $ */ ?>
<div class ='js-response'>
<div class="projectFunds index">
<h3><?php echo __l('Pledged Projects'); ?></h3>
<div class="clearfix">
                       <?PHP
                         if($is_wallet_enabled)
                         {
                            $link1 = "Backed";
                            $link2 = "Refunded";
                            $link3 = 'Funded';
                            $link ="Refunded";
							$link4 = "Failed";
                         }
                           else
                           {
                            $link1 = "Authorized";
                            $link2 = "Voided";
                            $link3 = 'Captured';
                             $link ="Voided";
							 $link4 = "Failed";
                           }
                        ?>
<ul class="filter-list-block clearfix">
     <?php $class=(empty($this->request->params['named']['status']) && !empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'mydonations')?'active':'';?>
        <li  class= "js-pagination <?php echo $class; ?>"><span class="import-block" title="<?php echo __l('All'); ?>"><?php echo $this->Html->link($this->Html->cInt($fund_count,false).'<span>' .__l('All'). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'mydonations'), array('escape' => false));?></span> </li>
		<?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'mydonations' && !empty($this->request->params['named']['status'])&& $this->request->params['named']['status'] == 'backed')?'active':'';?>
        <li  class= "js-pagination <?php echo $class; ?>"><span class="blue-block" title="<?php echo __l($link1); ?>"><?php echo $this->Html->link($this->Html->cInt($backed_count,false).'<span>' .__l($link1). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'mydonations', 'status' => 'backed'), array('escape' => false));?></span> </li>

		<?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'mydonations' && !empty($this->request->params['named']['status'])&& $this->request->params['named']['status'] == 'refunded')?'active':'';?>
		
        <li  class= "js-pagination <?php echo $class; ?>"><span class="red-block" title="<?php echo __l($link2); ?>"><?php echo $this->Html->link($this->Html->cInt($refunded_count,false).'<span>' .__l($link2). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'mydonations', 'status' => 'refunded'), array('escape' => false));?></span> </li>

		<?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'mydonations' && !empty($this->request->params['named']['status'])&& $this->request->params['named']['status'] == 'paid')?'active':'';?>
        <li  class= "js-pagination <?php echo $class; ?>"><span class="green-block" title="<?php echo __l($link3); ?>"><?php echo $this->Html->link($this->Html->cInt($paid_count,false).'<span>' .__l($link3). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'mydonations', 'status' => 'paid'), array('escape' => false));?></span> </li>
		
		<?php $class=(!empty($this->request->params['named']['type']) && $this->request->params['named']['type'] == 'mydonations' && !empty($this->request->params['named']['status'])&& $this->request->params['named']['status'] == 'failed')?'active':'';?>
        <li  class= "js-pagination <?php echo $class; ?>"><span class="green-block" title="<?php echo __l($link4); ?>"><?php echo $this->Html->link($this->Html->cInt($failed_count,false).'<span>' .__l($link4). '</span>', array('controller'=>'project_funds','action'=>'index','type' => 'mydonations', 'status' => 'failed'), array('escape' => false));?></span> </li>
</ul>
</div>
<?php  $this->element('paging_counter');?>
<table class="list">
<tr>
	<th class="js-pagination dl"><?php echo __l('Actions');?></th>
	<th class="js-pagination dl"><?php echo $this->Paginator->sort(__l('Project'),'project_id',array('url'=>array('controller'=>'project_funds','action'=>'index','type' => 'mydonations')));?></th>
	<th class="js-pagination dc"><div class="js-pagination"><?php echo $this->Paginator->sort(__l('Collected'), 'collected_amount',array('url' => array('controller' => 'project_funds', 'action' => 'index','type' => 'mydonations')));?></div> / <?php echo $this->Paginator->sort(__l('Needed Amount'), 'needed_amount', array('url' => array('controller' => 'project_funds', 'action' => 'index', 'type' => 'mydonations'))) . ' (' . Configure::read('site.currency') . ')';?></th>
	<th class="js-pagination dr"><?php echo $this->Paginator->sort(__l('Amount') . ' (' . Configure::read('site.currency') . ')' , 'amount',array('url'=>array('controller'=>'project_funds','action'=>'index','type' => 'mydonations')));?></th>
    <th class="js-pagination"><?php echo __l('Payment Status');?></th>
    <th class="js-pagination dc"><?php echo $this->Paginator->sort(__l('Pledged on'),'created',array('url'=>array('controller'=>'project_funds','action'=>'index','type' => 'mydonations')));?></th>
    <th class="js-pagination dl"><?php echo __l('Reward');?></th>
	<th class="js-pagination dl"><?php echo __l('Reward Status');?></th>
	
	
</tr>
<?php
if (!empty($projectFunds)):
$i = 0;
foreach ($projectFunds as $projectFund):
	$class = null;
	if ($i++ % 2 == 0) {
		$class = ' class="altrow"';
	}
                 $refund = __l('Funded');

                   if(($projectFund['ProjectFund']['payment_gateway_id'] == ConstPaymentGateways::PayPal))
						 {
                            if($projectFund['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding)
                               {
                                 $refund = __l('Authorized');
                               }
                               else
                               {
                                 $refund = __l('Captured');
                               }
                        }
                        else
                        {
                             if($projectFund['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding)
                               {
                                 $refund = __l('Pledged');
                               }
                               else
                               {
                                 $refund = __l('Funded');
                               }
                        }
					if(!empty($projectFund['ProjectFund']['is_failed'])) {
						$refund = __l('Failed');
						$class = ' class="altrow  js-faild"';
					} elseif(!empty($projectFund['ProjectFund']['is_failed'])) {
						$refund = __l('Cancelled');
						$class = ' class="altrow  js-faild"';
					}elseif(!empty($projectFund['ProjectFund']['is_cancelled'])) {
                         if(($projectFund['ProjectFund']['payment_gateway_id'] == ConstPaymentGateways::PayPal))
						 {
						    $refund = 'Voided';
                         }
                         else
                         {
                            $refund = 'Refunded';
                         }
                         if($projectFund['ProjectFund']['is_canceled_from_paypal'])
                         {
                           $refund.= '(From Paypal)';
                         }
                         $refund = __l($refund);
					}

?>
	<tr<?php echo $class;?>><td class="dl actions">
		<div class="action-block">
                <span class="action-information-block">
                    <span class="action-left-block">&nbsp;&nbsp;</span>
                        <span class="action-center-block">
                            <span class="action-info">
                                <?php echo __l('Action');?>
                             </span>
                        </span>
                    </span>
                    <div class="action-inner-block">
                    <div class="action-inner-left-block">
                        <ul class="action-link clearfix">
			<?php if ($projectFund['ProjectFund']['user_id'] == $this->Auth->user('id') && (Configure::read('Project.is_allow_pledge_cancel_by_backer')) && (strtotime('+'.Configure::read('Project.minimum_days_before_pledge_cancel').' days') < strtotime($projectFund['Project']['project_funding_end_date'].'23:59:59'))  && $projectFund['Project']['project_status_id'] == ConstProjectStatus::OpenForFunding): ?>
					<?php
						if (!$projectFund['ProjectFund']['is_cancelled'] && !$projectFund['ProjectFund']['is_refunded']) :
						?>
						<li><span>
						<?PHP
							$link = __l('Cancel and Refund');
							$type = 'cancel';
							echo $this->Html->link($link, array('controller'=> 'project_funds', 'action' => 'edit_fund', 'project_fund' => $projectFund['ProjectFund']['id'], 'type' => $type, 'return_page' => 'mydonations'), array('escape' => false,'class' => 'cancel js-delete','title'=>$link));
                    ?>
                      </span></li>
            <?PHP endif;?>


			<?php endif; ?>
			<li>
			<?php
				echo $this->Html->link(__l('Contact project owner'), array('controller' => 'messages', 'action' => 'compose', 'user' => $projectFund['Project']['User']['username'],'project_id'=>$projectFund['ProjectFund']['project_id']), array('class' => 'js-colorbox cboxelement msg', 'escape' => false,'title'=>__l('Contact project owner')));
			?>
			</li>
				<?php
					if (!empty($projectFund['ProjectFund']['project_reward_id']) && ($projectFund['Project']['project_status_id'] == ConstProjectStatus::FundingClosed || $projectFund['Project']['project_status_id'] == ConstProjectStatus::GoalReached || $projectFund['Project']['project_status_id'] == ConstProjectStatus::ReserveAmountReached) && empty($projectFund['ProjectFund']['is_given']) && empty($projectFund['ProjectFund']['is_refunded'])):
				?>
					<li><span><?php echo $this->Html->link(__l('Print voucher'), array('controller' => 'project_funds', 'action' => 'view', $projectFund['ProjectFund']['id'],'type'=>'print'), array('escape' => false,'target'=>'_blank','title'=>__l('Print voucher'), 'class' => 'print-voucher')); ?></span></li>
				<?php endif; ?>
				</ul>
    					</div>
    					<div class="action-bottom-block"></div>
    				  </div>
              </div>
			</td>
			<td class="dl">
			<?PHP
                         if($is_wallet_enabled)
                         {
                            $project_status = $projectFund['Project']['ProjectStatus']['name'];
                         }
                           else
                           {
                             $project_status = str_replace("Refunded","Voided",$projectFund['Project']['ProjectStatus']['name']);
                           }
            ?>
				<span class="project-status-info project-status-<?php echo $projectFund['Project']['project_status_id']; ?>" title="<?php echo $this->Html->cText($project_status,false);?>">
				    <?php echo $this->Html->cText($projectFund['Project']['ProjectStatus']['name'],false);?>
				</span>
				<?php echo $this->Html->link($this->Html->cText($projectFund['Project']['name']), array('controller'=> 'projects','action' => 'view', $projectFund['Project']['slug']), array('class' => 'js-colorbox cboxelement', 'escape' => false,'title'=> $this->Html->cText($projectFund['Project']['name'],false)));?>
			</td>
			<td class="dr">
				<?php $collected_percentage = ($projectFund['Project']['collected_percentage']) ? $projectFund['Project']['collected_percentage'] : 0; ?>
				<div class="progress-block round-5">
					<p class="progress-bar progress-bar-amount round-5" title = '<?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?>'>
						<span class="round-5" style="width:<?php echo ($collected_percentage > 100) ? '100%' : $collected_percentage.'%'; ?>;" title = "<?php echo $this->Html->cFloat($collected_percentage,false).'%'; ?>"><?php echo Configure::read('site.currency').$projectFund['Project']['collected_amount'];?>
						</span>
					</p>
					<p><?php echo $this->Html->cCurrency($projectFund['Project']['collected_amount']); ?> /
					<?php echo $this->Html->cCurrency($projectFund['Project']['needed_amount']); ?></p>
				</div>
            </td>
			<td class="dr"><?php echo $this->Html->cCurrency($projectFund['ProjectFund']['amount']);?></td>
			<td class="dc"><?php echo $this->Html->cText($refund);?></td>
            <td class="dc"><?php echo $this->Html->cDateTimeHighlight($projectFund['ProjectFund']['created']);?></td>
            <td class="dl"><span class="rewarded"><?php echo $this->Html->cText(!empty($projectFund['ProjectReward']['reward'])?$projectFund['ProjectReward']['reward']:__l('No reward selected'));?></span></td>
            <td class="dl">
				<?php
					if (!empty($projectFund['ProjectFund']['project_reward_id']) && ($projectFund['Project']['project_status_id'] == ConstProjectStatus::FundingClosed || $projectFund['Project']['project_status_id'] == ConstProjectStatus::GoalReached || $projectFund['Project']['project_status_id'] == ConstProjectStatus::ReserveAmountReached) && empty($projectFund['ProjectFund']['is_given'])):
				?>
					<p><span><?php echo __l('Not received'); ?></span></p>
				<?php endif; ?>
				<?php if (!empty($projectFund['ProjectFund']['is_given'])): ?>
					<p><span><?php echo __l('Received'); ?></span></p>
				<?php endif; ?>
			</td>
			
	</tr>
<?php
    endforeach;
else:
?>
	<tr>
		<td colspan="8" class="notice"><?php echo __l('No projects available');?></td>
	</tr>
<?php
endif;
?>
</table>
<div  class="js-pagination">
<?php
if (!empty($projectFunds)) {
    echo $this->element('paging_links');
}
?>
</div>
</div>
</div>